//
//  TerminalEquipmentViewController.m
//  JiuLe
//
//  Created by 黄鑫 on 16/8/30.
//  Copyright © 2016年 Fine. All rights reserved.
//

#import "TerminalEquipmentViewController.h"

@interface TerminalEquipmentViewController ()
@property (weak, nonatomic) IBOutlet UILabel *labDay;
@property (weak, nonatomic) IBOutlet UILabel *labActive;
@property (weak, nonatomic) IBOutlet UILabel *labSerialNumber;
@property (weak, nonatomic) IBOutlet UILabel *labExpire;

@end

@implementation TerminalEquipmentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"久乐表信息";
    [self showNavgationWithLeftItemWithTitle:@"我的"];
    self.labSerialNumber.text = [[NSUserDefaults standardUserDefaults] objectForKey:TerminalEquipment];
    [self getTerminalEquipment];
}

#pragma mark - 数据请求
- (void)getTerminalEquipment{
    [SVProgressHUD showWithStatus:@"获取设备信息..." maskType:SVProgressHUDMaskTypeClear];
    [[BaseDataRequest alloc] queryWatchinfowithBlock:^(id responseObject, NSString *status, NSError *error) {
        [SVProgressHUD dismiss];
        if ([status isEqualToString:@"0"]) {
            //[SVProgressHUD showSuccessWithStatus:@"获取设备信息成功!"];
            NSDictionary *dic = [responseObject objectForKey:@"result"];
            self.labDay.text = [NSString stringWithFormat:@"%@ 天",[dic objectForKey:@"days_wear"]];
            if ([[dic objectForKey:@"active_date"] isEqualToString:@""]) {
                self.labActive.text = @"";
            }else{
                self.labActive.text = [NSString stringWithFormat:@"%@",[self timeStamp:[dic objectForKey:@"active_date"]]];
            }
            if ([[dic objectForKey:@"expire_date"] isEqualToString:@""]) {
                self.labExpire.text = @"";
            }else{
                self.labExpire.text = [NSString stringWithFormat:@"%@",[self timeStamp:[dic objectForKey:@"expire_date"]]];
            }
        }else{
            if (error != nil) {
                TIPSFORVIEW(@"请检测网络设置");
            }else{
                NSString *message = [responseObject objectForKey:@"message"];
                if ([message isEqualToString:@""]) {
                    TIPSFORVIEW(@"获取设备信息失败");
                }else{
                    TIPSFORVIEW(message);
                }
            }
        }
    }];
}

#pragma  mark - UITableViewDataSource
/*
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *identifier = [NSString stringWithFormat:@"terminalEquipmentVCCellID%d",indexPath.row];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] ;
    }
    return cell;
}*/

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (NSString *)timeStamp:(NSString *)strTime{
    NSTimeInterval time=[strTime doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec
    NSDate*detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString*currentDateStr = [dateFormatter stringFromDate:detaildate];
    return currentDateStr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
